const express = require('express');
const {createProxyMiddleware} = require('http-proxy-middleware')

const BASE_URL = `${process.env.API_PREFIX}`

let app = express()
let port = 4000

app.all('*', (req, res, next) => {
    res.header('access-control-allow-origin', "*")
    res.header('access-control-allow-credentials', 'true')
    res.header('access-control-allow-methods', '*')
    res.header('access-control-allow-headers', '*')
    if (req.method.toUpperCase() == 'OPTIONS') {
        res.send(200)
    } else {
        next()
    }
})

app.use(
    '/api',
    createProxyMiddleware({
        target: 'https://pay-admin.gdjdtec.com',
        pathRewrite: {'^/api': ''},
        changeOrigin: true,
    }));


app.listen(port, err => {
    if (err) {
        throw err
    }
    console.log(`> Ready on http://localhost:${port}`)
})
